package com.lipaluma.test.db.internal.loadData;

import com.lipaluma.test.db.annotations.LoadDataInfile;

public class LoadDataInfileParams {

	/**
	 * Emplacement du dossier contenant les fichiers à loader dans la base
	 */
	private String folderPath;
	
	/**
	 * Séparateur entre chaque champ du fichier
	 */
	private String fieldDelimiter;

	/**
	 * Séparateur entre chaque champ du fichier
	 */
	private String fieldEnclosedBy;

	/**
	 * Séparateur entre chaque ligne du fichier
	 */
	private String linesDelimiter;

	/**
	 * Indique si le fichier de données contient une ligne entête avec les noms des colonnes à injecter
	 */
	private boolean headers;
	
	private LoadDataInfileParams(Builder builder) {
		this.folderPath = builder.folderPath;
		this.fieldDelimiter = builder.fieldDelimiter;
		this.fieldEnclosedBy = builder.fieldEnclosedBy;
		this.linesDelimiter = builder.linesDelimiter;
		this.headers = builder.headers;
	}

	public String getFolderPath() {
		return folderPath;
	}

	public String getFieldDelimiter() {
		return fieldDelimiter;
	}

	public String getFieldEnclosedBy() {
		return fieldEnclosedBy;
	}

	public String getLinesDelimiter() {
		return linesDelimiter;
	}

	public boolean hasHeaders() {
		return headers;
	}

	public static Builder builder() {
		return new Builder();
	}
	
	public static class Builder {
		private String folderPath;
		private String fieldDelimiter;
		private String fieldEnclosedBy;
		private String linesDelimiter;
		private boolean headers;

		public Builder fromAnnotation(LoadDataInfile loadDataInfile) {
			this.folderPath = loadDataInfile.value();
			this.fieldDelimiter = loadDataInfile.fieldDelim();
			this.fieldEnclosedBy = loadDataInfile.fieldEnclosed();
			this.linesDelimiter = loadDataInfile.linesDelim();
			this.headers = loadDataInfile.headers();
			return this;
		}

		public Builder filesOnPath(String folderPath) {
			this.folderPath = folderPath;
			return this;
		}
		
		public Builder fieldDelimitedBy(String delimiter) {
			this.fieldDelimiter = delimiter;
			return this;
		}
		public Builder fieldEnclosedBy(String enclosedBy) {
			this.fieldEnclosedBy = enclosedBy;
			return this;
		}
		public Builder linesDelimitedBy(String delimiter) {
			this.linesDelimiter = delimiter;
			return this;
		}
		public Builder withHeaders(boolean headers) {
			this.headers = headers;
			return this;
		}
		
		public LoadDataInfileParams build() {
			return new LoadDataInfileParams(this);
		}
	}
}
